define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sharemoney/index' + location.search,
                    add_url: 'sharemoney/add',
                    edit_url: 'sharemoney/edit',
                    // del_url: 'sharemoney/del',
                    multi_url: 'sharemoney/multi',
                    import_url: 'sharemoney/import',
                    table: 'share_money',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'user_level', title: __('User_level'), searchList: { 1: 'V1', 2: 'V2', 3: 'V3', 4: 'V4', 5: 'V5', 6: 'V6' },formatter:Table.api.formatter.normal},
                        {field: 'expert_level', title: __('Expert_level'), searchList: { 0: '其他',1: '团长', 2: '家庭酒庄', 3: '区县代理商' },formatter:Table.api.formatter.normal},
                        {field: 'rate', title: __('Rate'),searchable: false},
                        {field: 'h5_money', title: __('H5_money'),searchable: false, operate:'BETWEEN'},
                        {field: 'score', title: __('Score'),searchable: false},
                        {field: 'order_price', title: __('Order_price'),searchable: false},
                        {field: 'type', title: __('Type'), searchList: { 1: 'v1~v6分佣', 2: '家庭酒庄分佣' },formatter:Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: { 0: '已退单',1: '正常' },formatter:Table.api.formatter.status},
                        {field: 'update_time', title: __('Update_time'),searchable: false,  operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
